
local lni_c = require 'jass.lni'
local storm = require 'jass.storm'
local loadfile = storm.load 
local savefile = storm.save 

local mt = {}

ac.lni = setmetatable({ 
	object = {},
},{
	__index = mt,
	__call = function(self, pkey, ckey,value)
		local pdata = self.object[pkey]
		if pdata then 
			if not ckey then 
				return pdata
			end
            if value then
                pdata[ckey] = value
            end
			return pdata[ckey]
		end 
	end,
})

function mt:load()

	self.object = { }

	local buff = loadfile '.iniconfig'
	if not buff then 
		return 
	end

	local iniconfig = lni_c (buff)

	local data = {}
	local default 
	local enum 

	local function packager (fullpath, default, enum)
		local content = loadfile(fullpath)
		if content then
			data, default, enum = lni_c(content, fullpath, {data, default, enum} )
		else
			print( fullpath, content and #content or "ini文件丢失")
		end
	end 

	for name, list in pairs(iniconfig) do
		for i = 1, #list do 
			packager(list[i], default, name)
		end 

		if ac.safemode == true then 
			for name in pairs(data) do
				local safename = ("%s(safe)"):format(name) 
				local safedata = data[safename]
				if safedata then 
					-- print("和谐", name, safename)
					data[name] = safedata
				end 
			end 
		end 

		self.object[name] = data
		data = {}
	end

end 

ac.game:on "游戏-热更新" ( function() 
	ac.lni:load() 
end )

ac.lni:load() 


return ac.lni